package com.redroid.findme;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AddSnListAdapter extends ArrayAdapter<AddSnActItemHandler>{
	
	Context _context;
	int _layoutResourceId;
	AddSnActItemHandler[] _data;
		
		public AddSnListAdapter(Context context, int layoutResourceId, 
				AddSnActItemHandler[] data){
				super(context, layoutResourceId, data);
				this._context = context;
				this._layoutResourceId = layoutResourceId;
				this._data = data;
		}
	
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
		
			View row = convertView;
			AddSnItemHandlerHolder holder = null;
			
			if (row == null) {
				
				LayoutInflater inflater = ((Activity)_context).getLayoutInflater();
				row = inflater.inflate(_layoutResourceId, parent, false);
				
				holder = new AddSnItemHandlerHolder();
				holder.imgIcon = (ImageView)row.findViewById(R.id.addsnitemimg);
				holder.txtTitle = (TextView)row.findViewById(R.id.addsnitemlabel);
				
				row.setTag(holder);
			} else {
				holder = (AddSnItemHandlerHolder)row.getTag();
			}
				
			AddSnActItemHandler item = _data[position];
			holder.txtTitle.setText(item._snlabel);
			holder.imgIcon.setImageResource(item._icon);
			
			return row;
		}
		
	static class AddSnItemHandlerHolder{
		ImageView imgIcon;
		TextView txtTitle;
	}
}
